<script language="JavaScript">
//<!--
var tableName = "processes_ration_maint";	
var mObjs = ["m1_year_output","m1_material_weight","m1_single","m2_before_instance",
			  "m3_lifespan_use","m3_install_dust","m4_year_output","m4_avg_deal_value",
			  "m4_used_time"];
function f_initOther() {
	var methodTypeObj = document.all(tableName+".method_type");
	var consumeValueObj = document.all(tableName+".consume_value");
	var consumeValue = consumeValueObj.value;
	methodTypeObj.onchange = function(){ showHideFieldSet(this); };
	showHideFieldSet(document.all(tableName+".method_type"));
	for(var i = 0, len = mObjs.length; i < len; i++){
		document.all(tableName+"."+mObjs[i]).onblur = countConsumeValue;
	}
	consumeValueObj.value=consumeValue;
	//var shortestCycleObj = document.all(tableName+".shortest_cycle");
	//shortestCycleObj.readOnly = true;
	//shortestCycleObj.className = "formDisabled";
}

function showHideFieldSet(methodTypeObj){
	var methodType = methodTypeObj.value;
	if (!methodType) return;
	for(var i = 0; i < 4; i++){
		var fieldsetObj = document.getElementById("prm.label.method."+(i+1));
		var tableObj = fieldsetObj.childNodes[1];
		var inputObjs = tableObj.getElementsByTagName("input");
		fieldsetObj.style.display = i == methodType ? "block" : "none";
		if (i != methodType){
			for(var j = 0; j < inputObjs.length; j++){
				inputObjs[j].value="";
			}
		}
	}
	document.all(tableName+".consume_value").value = 0.0;
}

function f_save2(){
	var isPass = true;
	var methodType = document.all(tableName+".method_type").value;
	var start = -1;
	var end = -1;
	if (0 == methodType){
		start = 0;
		end = start + 3;
	}
	else if (1 == methodType){
		start = 3;
		end = start + 1;
	}
	else if (2 == methodType){
		start = 4;
		end = start + 2;
	}
	else if (3 == methodType){
		start = 6;
		end = start + 3;
	}
	for(var i = start; i < end; i++){
		var valueObj = document.all(tableName+"."+mObjs[i]);
		var value = valueObj.value;
		if (!value){
			isPass = false;
			var valueTdObj = valueObj.parentNode;
			var trObj = valueTdObj.parentNode;
			var index = -1;
			var tdObjs = trObj.childNodes;
			for(var j = 0, len = tdObjs.length; j < len; j++){
				if (tdObjs[j] == valueTdObj){
					index = j - 1;
					break;
				}
			}
			alert('<eam:message key="sjtotal.err.input" />'+tdObjs[index].innerHTML);
			valueObj.focus();
			break;
		}
	}
	if (isPass) f_save();
}

function countConsumeValue(){
	var methodType = document.all(tableName+".method_type").value;
	var consumeValueObj = document.all(tableName+".consume_value");
	if (0 == methodType){
		consumeValueObj.value = countMothod1();
	}
	else if (1 == methodType){
		consumeValueObj.value = countMothod2();
	}
	else if (2 == methodType){
		consumeValueObj.value = countMothod3();
	}
	else if (3 == methodType){
		consumeValueObj.value = countMothod4();
	}
}

function countMothod1(){
	var m1_year_output = getFloatValue("m1_year_output");
	var m1_material_weight = getFloatValue("m1_material_weight");
	var m1_single = getFloatValue("m1_single");
	if ((m1_material_weight * m1_single) == 0.0){
		return 0.0;
	}
	else{
		return m1_year_output / m1_material_weight * m1_single;
	}
}

function countMothod2(){
	return getFloatValue("m2_before_instance");
}

function countMothod3(){
	var m3_lifespan_use = getFloatValue("m3_lifespan_use");
	var m3_install_dust = getFloatValue("m3_install_dust");
	if (m3_lifespan_use == 0.0){
		return 0.0;
	}
	else{
		return (12 / m3_lifespan_use) * m3_install_dust;
	}
}

function countMothod4(){
	var m4_year_output = getFloatValue("m4_year_output");
	var m4_avg_deal_value = getFloatValue("m4_avg_deal_value");
	var m4_used_time = getFloatValue("m4_used_time");
	if ((m4_avg_deal_value * m4_used_time) == 0.0){
		return 0.0;
	}
	else{
		return m4_year_output / (m4_avg_deal_value * m4_used_time);
	}
}

function getFloatValue(colName){
	colName = tableName+"."+colName;
	var value = document.all(colName).value;
	return value ? parseFloat(value) : 0.0;
}
//-->
</script>